<?php

namespace api\controller;

use think\Exception;
use think\Request;
use common\controller\VerifyController;
use common\service\TaskLibraryViewConfigService;
use think\Response;

class TaskLibraryViewConfigController extends VerifyController
{

    /**
     * @var TaskLibraryViewConfigService
     */
    private TaskLibraryViewConfigService $TaskLibraryViewConfigService;

    public function __construct()
    {
        parent::__construct();
        $this->TaskLibraryViewConfigService = TaskLibraryViewConfigService::getInstance();
    }

    /**
     * 任务库V2列表查询
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function updateSortIndex(Request $request)
    {
        $param = $request->param();
        $res = $this->TaskLibraryViewConfigService->updateSortIndex($param['data']);
        return json(success_response('', $res));
    }

    /**
     * 创建
     * @param Request $request
     * @return Response
     */
    public function create(Request $request)
    {
        $type = $request->param()['data']['type'];
        // 处理非需求单延期单的排序规则
        if ($type != 'demand_order_delay_order') {
            $this->TaskLibraryViewConfigService->createSortIndex();
        }
        return parent::create($request); // TODO: Change the autogenerated stub
    }

    /**
     * 需求延期单配置
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function demandOrderDelayOrderList(Request $request)
    {
        $param = $request->param();
        $res = $this->TaskLibraryViewConfigService->demandOrderDelayOrderList($param['param']);
        return json(success_response('', $res));
    }

}
